<template>
  <div class="custom-body" :style="borderStyle">
    <el-empty v-if="dataList === null || dataList.length === 0" class="custom-right" :image-size="100" />
    <div v-else class="custom-right">
      <div v-for="(item,index) in dataList" :key="'li-'+index" class="custom-ul-li" :style="liStyle">
        <div
          class="custom-ul-body"
          :style="{
            boxShadow: '0 2px 7px 0px '+ item.backColorA,
            background: 'linear-gradient(0deg,'+item.backColorA+','+item.backColorB+')' }"
        >
          <div class="custom-li-image">
            <el-image class="li-image" :src="baseURL+item.tb.substring(1,item.tb.length)" />
          </div>
          <div class="custom-li-right">
            <div class="custom-li-line" @click="callBack(item)">
              <span class="left" :style="{ color: item.titleColor, fontSize: item.titleFontSize + 'px' }">{{ item.label }}</span>
              <span class="right" :style="{ color: item.fontColor, fontSize: item.fontSize + 'px',fontWeight: '600' }">
                <statistics-slot :ids="item.sjly.id" :column="item.number" />
              </span>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import StatisticsSlot from './slot/statistics';
import { queryEntity } from '@/api/portal/manager/columnTemp';
export default {
  name: 'PortalNewPcStatisticsV1',
  components: { StatisticsSlot },
  props: {
    temp: {
      type: Object,
      default() {
        return {};
      }
    },
    showHeader: {
      type: Boolean,
      default: true
    },
    layout: {
      type: Object,
      default: () => {
        return {};
      }
    }
  },
  data() {
    return {
      column: [],
      dataList: [],
      baseURL: process.env.VUE_APP_BASE_API, // api 的 base_url
      customStyle: {},
      titleStyle: {},
      bodyStyle: {},
      call: {}
    };
  },
  computed: {
    borderStyle() {
      if (this.temp.sfdzqp === true) {
        return { position: 'absolute', left: '0px', right: '0px', top: '0px', bottom: '0px' };
      }
      return { height: this.temp.defaultHeight };
    },
    liStyle() {
      const width = (100 / this.column.size).toFixed(2);
      return { width: width + '%' };
    }
  },
  watch: {
    layout: {
      handler(newData, oldData) {
        this.customStyle = newData;
        this.titleStyle = { backgroundColor: newData.mrlb, opacity: newData.tmd };
      },
      immediate: true, // 父组件第一次传值时，执行handler，false则第一次不执行
      deep: false // formType为对象时，设置为true，此属性监听对象发生变化
    },
    temp: {
      handler(newData, oldData) {
        if (this.showHeader) {
          const pzx = JSON.parse(newData.data.pzx);
          this.column = pzx;
          this.dataList = pzx.data;
        } else {
          const pzx = JSON.parse(newData.pzx);
          this.column = pzx;
          this.dataList = pzx.dataList;
          // this.initData(newData.id)
        }
      },
      immediate: true, // 父组件第一次传值时，执行handler，false则第一次不执行
      deep: false // formType为对象时，设置为true，此属性监听对象发生变化
    }
  },
  methods: {
    initEntity(id, label) {
      if (id !== null) {
        queryEntity({ id: id }).then(res => {
          const { data } = res;
          this.call = data;
          this.call.menuId = this.temp.menu.id;
          this.call.menuName = this.temp.menu.name;
          this.call.showHeader = true;
          this.call.columnName = label;
          this.$emit('fetch-data', this.call);
        });
      }
    },
    callBack(item) {
      if (item.isOpenMore === true) {
        if (item.openType === 1) { // 模版的方式打开
          this.initEntity(item.temp, item.label);
        }
        if (item.openType === 2 && undefined !== item.openUrl && item.openUrl !== null) {
          window.open(item.openUrl, '_blank');
        }
      }
      /* if (undefined !== item) {
        item.menuId = this.temp.menu.id
        item.menuName = this.temp.menu.name
        item.showHeader = true
        this.$emit('fetch-data', item)
      } */
    }
  }
};
</script>

<style scoped>
.custom-body {
  width: 100%;
  height: 100%;
  position: relative;
  display: flex;
  flex-flow: row nowrap;
  background-color: #ffffff;
  border-radius: 4px;
  box-sizing: border-box;
  overflow: hidden;
}
.custom-right {
  flex: 1 1 auto;
  height: 100%;
  display: flex;
  flex-flow: row wrap;
}
.custom-ul-li {
  flex: 0 1 auto;
  box-sizing: border-box;
  height: 60px;
  padding: 5px ;
  box-sizing: border-box;
}
.custom-ul-body{
  width: 100%;
  height: 100%;
  border-radius: 4px;
  position: relative;
  box-sizing: border-box;
  display: flex;
  flex-flow: row nowrap;
}
.custom-li-image {
  flex: 0 1 auto;
  width: 60px;
  text-align: center;
}
.li-image {
  width: 40px;
  margin-top: 5px;
}
.custom-li-right {
  flex: 1 1 auto;
  height: 100%;
  box-sizing: border-box;
  position: relative;
}
.custom-li-line {
  width: 100%;
  height: 100%;
  display: flex;
  flex-flow: row nowrap;
  line-height: 50px;
}
.custom-li-line span{
  width: 100%;
  height: 100%;
  line-height: 50px;
  text-align: center;
  padding: 0px 5px;
  box-sizing: border-box;
}
.custom-li-line span.left {
  text-align: left;
}
.custom-li-line span.right {
  text-align: right;
  padding-right: 15px;
  box-sizing: border-box;
}
</style>
